package com.example.as_sum.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.as_sum.R;
import com.example.as_sum.application.AppApplication;
import com.example.as_sum.util.toast.ToastUtil;

import java.util.Random;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by ran on 2016/7/20.
 */
public class MainTwoFragment extends BaseFragment {
    private TextView fragment_tv;

    public static MainTwoFragment newInstance() {
        MainTwoFragment fragment = new MainTwoFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_two, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    private Handler mHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            closeDialog();
            switch (msg.what) {
                case 0:
                    fragment_tv.setTextColor(Color.BLUE);
                    fragment_tv.setTextSize(20);
                    Random random = new Random();
                    int code = random.nextInt(100);
                    fragment_tv.setText("刷新完成了...，随机值：" + code);
                    break;
                case 1:
                    break;
            }
            return false;
        }
    });

    @Override
    public void fetchData() {
        showDialog("刷新中...", false);
        mHandler.sendEmptyMessageDelayed(0, 1000);
    }

    @Override
    public void initView(View view) {
        fragment_tv = (TextView) view.findViewById(R.id.fragment_two_tv);
    }

    @Override
    public void addListener() {

    }

    @Override
    public void setParam() {

    }

    @Override
    public Handler getUIHandler() {
        return null;
    }

    @Override
    protected void loadUIData() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.fragment2_brn, R.id.fragment2_btn2, R.id.fragment2_btn3,
            R.id.fragment2_btn4,R.id.fragment2_btn5})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fragment2_brn:
                ToastUtil.makeText(getActivity(),"WindowManger添加布局",1000).show();
                break;
            case R.id.fragment2_btn2:
                break;
            case R.id.fragment2_btn3:
                break;
            case R.id.fragment2_btn4:
                break;
            case R.id.fragment2_btn5:
                AppApplication.aContext.setToken("1111111");
                break;
        }
    }
}
